<!--
* @description 人员分数统计列表
* @fileName scoreList.vue
* @author huangyu
* @date 2023/02/28 22:17:17
!-->
<template>
    <div>
        <div style="margin-bottom:10px;">
            <el-button type="primary" @click="addPersonTotal">新增人员分数统计</el-button>
            <el-button type="primary" @click="getData">刷新</el-button>
        </div>
         <el-table :data="list" max-height="650px">
             <el-table-column type="index" label="序号"></el-table-column>
             <el-table-column label="统计标题" prop="title"></el-table-column>
             <el-table-column label="本次积分" prop="score"></el-table-column>
             <el-table-column label="创建时间" prop="createTime"></el-table-column>
             <el-table-column label="相关人员明细">
                <template slot-scope="scope"><strong class="color_link" @click="clickPersonDetail(scope.row)">{{scope.row.personIds.length}}</strong></template>
             </el-table-column>
             <el-table-column label="操作">
                <template slot-scope="scope">
                    <excel-export ref="excelExport" :sheet="sheet" :manual="true" :filename="filename"></excel-export>
                    <el-button type="primary" plain @click="getClanData(scope.row,true)" size="mini">导出名单</el-button>
                </template>
             </el-table-column>
         </el-table>

         <el-dialog title="人员分数统计" top="50px" :visible.sync="dialogPersonTotal" v-if="dialogPersonTotal" v-dialogDrag append-to-body>
            <vScoreTotal @getData="getData"></vScoreTotal>
         </el-dialog>

        <el-dialog title="参加名单" top="50px" :visible.sync="dialogPersonDetail" v-if="dialogPersonDetail" v-dialogDrag append-to-body>
            <el-row>
                <el-col :span="6" v-for="(item,index) in clanList" :key="index" style="line-height:28px;">{{item.name}} [{{item.house}}]</el-col>
            </el-row>
         </el-dialog>
    </div>
 </template>
 
 <script>
 import { get } from '@/common/app.js'
 import vScoreTotal from "./scoreTotal.vue"
 import { formatDate } from '@/common/unit.js'
 import {ExcelExport} from 'pikaz-excel-js'
 export default {
    components: {vScoreTotal,ExcelExport},
    data() {
        return {
          list: [],
          dialogPersonTotal: false,
          dialogPersonDetail: false,
          clanList: [],
          row: {},
          sheet: [],
          filename: "",
        }
    },
    mounted() {
        this.getData()
    },
    methods: {
        addPersonTotal(){
            this.dialogPersonTotal = true
        },
        getData(){
            let params = {
                type: "getClan",
                api: "api-clanscore-list",
                data: {},
            }
            get('game',params).then(res=>{
                if(res){
                    this.list = res.data
                    this.list.forEach(item=>{
                        if(item.crearTime){
                            item.createTime = formatDate(new Date(item.crearTime),'yyyy-MM-dd hh:mm:ss')
                        }
                    })
                    this.dialogPersonTotal = false
                }
            })
        },

        clickPersonDetail(row){
            this.row = row
            this.dialogPersonDetail = true
            this.getClanData(this.row)
        },
        getClanData(row,isDaoChu){
            let params = {
                type: "getClan",
                api: "api-clan-list",
                idsArr: row.personIds,
                data:{
                    pageIndex: 1,
                    pageSize: 100,
                }
            }
            get('game',params).then(res=>{
                if(res){
                    this.clanList = res.list
                    if(isDaoChu){
                        this.exportExcel(row)
                    }
                }
            })
        },
        exportExcel(row){
            console.log(this.clanList)
            this.filename = `${row.title}参加名单`
            this.sheet.push({
                //表头
                tHeader: ['名字','所属家族','职业'],
                //多级表头
                // multiHeader:[[第一行],[第二行]],
                //表头对应的keys
                keys:['name','house','sect'],
                //合并的单元格位置
                merges: [],
                table: this.clanList,
                colWidth:[],
                globalStyle: {
                    alignment: {
                        wrapText: false,
                    }
                },
            })
            // console.log(this.sheet)
            this.$refs.excelExport.pikaExportExcel()
        },
    },
 }
 </script>
 
 <style scoped>
 
 </style>